package DBHandle;

import java.util.*;
import java.io.*;

import com.opensymphony.xwork2.Action;

//自动补全功能类
//功能：1 model,2 region,3 city,4 venue_code,5 venue_type,6 product
public class AutoComplete
{
	private InputStream inputStream;
	private int name;
	
	public void setName(int name) {
        this.name = name;
    }
	
	public InputStream getInputStream() {
		return this.inputStream;
	}
	
	public String execute() throws Exception
	{
		General dbHandle=new General();
		ArrayList<String> temp=new ArrayList<String>();
		String s="[";
		switch (name) 
		{
			case 1:
				temp=dbHandle.SelectArrayList("name","qbx_model");
				break;
			case 2:
				temp=dbHandle.SelectArrayList("region", "qbx_region");
				break;
			case 3:
				temp=dbHandle.SelectArrayList("city", "qbx_region");
				break;
			case 4:
				temp=dbHandle.SelectArrayList("name", "qbx_venue_type");
				break;
			case 5:
				temp=dbHandle.SelectArrayList("venue_code", "qbx_vm");
				break;
			case 6:
				temp=dbHandle.SelectArrayList("item", "qbx_product");
				break;
			case 7:
				temp=dbHandle.SelectArrayList("qbx_number","qbx_vm");
				break;
			case 8:
				temp=dbHandle.SelectArrayList("alona_number", "qbx_vm");
				break;
			default:
				break;
		}
		
		for(String item:temp)
		{		
			s+="{'name':'"+item+"'},";
		}
		s=s.substring(0,s.length()-1);
		s+="]";
		inputStream=new StringBufferInputStream(s);
		return Action.SUCCESS;
	}	
}